package com.review.group.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.review.common.annotation.Log;
import com.review.common.core.controller.BaseController;
import com.review.common.core.domain.AjaxResult;
import com.review.common.enums.BusinessType;
import com.review.group.domain.ReviewGroup;
import com.review.group.service.IReviewGroupService;
import com.review.common.utils.poi.ExcelUtil;
import com.review.common.core.page.TableDataInfo;

/**
 * 小组Controller
 *
 * @author lls
 * @date 2022-03-16
 */
@RestController
@RequestMapping("/group/group")
public class ReviewGroupController extends BaseController
{
    @Autowired
    private IReviewGroupService reviewGroupService;

    /**
     * 查询小组列表
     */
    @PreAuthorize("@ss.hasPermi('group:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReviewGroup reviewGroup)
    {
        startPage();
        List<ReviewGroup> list = reviewGroupService.selectReviewGroupList(reviewGroup);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('group:group:list')")
    @GetMapping("/selectGroupUser")
    public AjaxResult  selectGroupUser(ReviewGroup reviewGroup)
    {
        Long [] list = reviewGroupService. selectGroupUser(reviewGroup);
        return AjaxResult.success(list);
    }


    /**
     * 导出小组列表
     */
    @PreAuthorize("@ss.hasPermi('group:group:export')")
    @Log(title = "小组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReviewGroup reviewGroup)
    {
        List<ReviewGroup> list = reviewGroupService.selectReviewGroupList(reviewGroup);
        ExcelUtil<ReviewGroup> util = new ExcelUtil<ReviewGroup>(ReviewGroup.class);
        util.exportExcel(response, list, "小组数据");
    }

    /**
     * 获取小组详细信息
     */
    @PreAuthorize("@ss.hasPermi('group:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(reviewGroupService.selectReviewGroupById(id));
    }

    /**
     * 新增小组
     */
    @PreAuthorize("@ss.hasPermi('group:group:add')")
    @Log(title = "小组", businessType = BusinessType.INSERT)
    @PostMapping("/addProjects")
    public AjaxResult addProjects(@RequestBody ReviewGroup reviewGroup)
    {
        return toAjax(reviewGroupService.addProjects(reviewGroup));
    }
    /**
     * 新增小组项目
     */
    @PreAuthorize("@ss.hasPermi('group:group:add')")
    @Log(title = "小组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReviewGroup reviewGroup)
    {
        return toAjax(reviewGroupService.insertReviewGroup(reviewGroup));
    }

    /**
     * 修改小组
     */
    @PreAuthorize("@ss.hasPermi('group:group:edit')")
    @Log(title = "小组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReviewGroup reviewGroup)
    {
        return toAjax(reviewGroupService.updateReviewGroup(reviewGroup));
    }

    /**
     * 删除小组
     */
    @PreAuthorize("@ss.hasPermi('group:group:remove')")
    @Log(title = "小组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reviewGroupService.deleteReviewGroupByIds(ids));
    }
    /**
     * 新增小组项目
     */
    @PreAuthorize("@ss.hasPermi('group:group:add')")
    @Log(title = "小组", businessType = BusinessType.INSERT)
    @PostMapping("/addGroupUsers")
    public AjaxResult addGroupUsers(@RequestBody ReviewGroup reviewGroup)
    {
        return toAjax(reviewGroupService.addGroupUsers(reviewGroup));
    }
}
